using System;
using System.Collections.Generic;


namespace Aima.Core.Util.math
{
    public class Vector : Matrix
    {
       
        // Vector is modelled as a matrix with a single column;  Constructs a vector with the specified size.
        public Vector(int size) : base(size, 1)
        {}

        // Constructs a vector with the specified list of values.
        public Vector(List<Double> lst) : base(lst.Count, 1)
        {
            for (int i = 0; i < lst.Count; i++)
            {
                this[i] = lst[i];
            }
        }

        // indexer
        public double this[int i]
        {
            get { return this[i, 0]; }
            set { this[i, 0] = value; }
        }

      

        // Returns a copy of this vector.
        public Vector CopyVector()
        {
            var result = new Vector(RowDimension);
            for (int i = 0; i < RowDimension; i++)
            {
                result[i]= this[i];
            }
            return result;
        }

        // Returns the number of values in this vector.
        public int Size()
        {
            return RowDimension;
        }

        // Returns the result of vector subtraction.
        public Vector Minus(Vector v)
        {
            var result = new Vector(Size());
            for (int i = 0; i < Size(); i++)
            {
                result[i]= this[i] - v[i];
            }
            return result;
        }

        // Returns the result of vector addition.
        public Vector Plus(Vector v)
        {
            var result = new Vector(Size());
            for (int i = 0; i < Size(); i++)
            {
                result[i]= this[i] + v[i];
            }
            return result;
        }

        // Returns the index at which the maximum value in this vector is located.
        public int IndexHavingMaxValue()
        {
            if (Size() <= 0)
            {
                throw new Exception("can't perform this op on empty vector");
            }
            int res = 0;
            for (int i = 0; i < Size(); i++)
            {
                if (this[i] > this[res])
                {
                    res = i;
                }
            }
            return res;
        }
    }
}